﻿window.UserInfo = User.extend({
    defaults: {
        MemLoginID: ''
    },
    urlRoot: 'api/account/',
    url: function () {
        return this.urlRoot + pageView.getCookieValue('uid');
    }
});

window.UserInfoView = Backbone.View.extend({
    el: "#jqt",
    initialize: function () {
        this.model = new UserInfo();
        this.template = $('#MyInfoTemplate').html();
    },

    events: {
        'click a.exit': 'logout',
        'click #myMenu a[action="myCollect"]': 'renderCollect',
        'click #myMenu a[action="myOrder"]': 'renderMyOrder',
        'click a.mymsg,#myMenu a[action="myMsg"]': 'renderMyMessage',
        'click #myMenu a[action="myCart"]': 'renderMyCart'
    },

    render: function () {
        var partial = { header: $('#HeaderTemplate').html(), footer: $('#FooterTemplate').html(),
            innerFooter: $('#InnerFooterTemplate').html(), menu: $('#InfoMenuTemplate').html()
        };
        var data = { title: "我的ShopNum1", btnListR: [{ name: 'avatar' }, { name: 'home'}] };

        this.$el.append(Mustache.render(this.template, data, partial));

        this.fetchUserInfo();

        return this;
    },

    fetchUserInfo: function () {
        var that = this,
            template = $('#InfoHeaderTemplate').html();

        this.model.fetch({
            success: function () {
                $('.info-header').html(Mustache.render(template, that.model.toJSON(), []));
                pageView.resizeScroll();
            }
        });


    },

    logout: function () {
        pageView.logout();
    },

    renderCollect: function () {
        pageView.goTo('MyCollect');
    },

    renderMyOrder: function () {
        pageView.goTo('MyOrder');
    },

    renderMyCart: function () {
        pageView.goTo('MyCart');
    },

    renderMyMessage: function () {
        localStorage.setItem('messagePageIndex', 1);
        pageView.goTo('MyMessage');
    }
});